<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  let url =
    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1585801677701&di=e464c885b588c313ce683c5b4c2317a5&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F14%2F75%2F01300000164186121366756803686.jpg";
  let img = new Image();
  img.src = url;
  img.onload = () => {
    // 当图片加载成功时，执行函数
    console.log(`图片成功了`);
  };
  img.onerror = () => {
    // 当图片加载失败时，执行的函数
    console.log(`图片出错了`);
  };
  let body = document.body;
  body.insertBefore(img, body.children[0]);
</script>

</html>